import Vue from "vue";
import App from "./App";
import store from "@/store";
import api from "./api";


import { wgs84ToGcj02ToBd09 } from "@/utils/wgs84ToBd09";
Vue.prototype.wgs84ToGcj02ToBd09 = wgs84ToGcj02ToBd09;

import reportApi from './api/modules/report'
import { getQueryString } from "@/utils/index.js";

import uView from "uview-ui";
import NuiStep from "@/components/step.vue";
import NuiGuide from "@/components/guide.vue";
Vue.use(uView);
Vue.component("NuiStep", NuiStep);
Vue.component("NuiGuide", NuiGuide);

Vue.config.productionTip = false;
Vue.prototype.$api = api;


Vue.prototype.$store = store;

App.mpType = "app";

window.onerror = (msg, url, l) => {
    let text = "发生错误";
    text += "Error: " + msg + "\n";
    text += "URL:" + url + "\n";
    text += "Line:" + l + "\n";
    let appId = uni.getStorageSync("appId");
    let openId = uni.getStorageSync('openId')
    let deptId = getQueryString("deptId") == null ? "0" : getQueryString("deptId")
    reportApi.errorReport({ error: text, appId: appId, openId: openId, deptId });
    return true
};

Vue.config.errorHandler = (error, vm, info) => {
    let text = "发生错误";
    text += "Error: " + error + " \n ";
    text += "Vue Component:" + vm.route + " \n ";
    text += "Info:" + info + " \n ";
    text += "Stack:" + error.stack;
    let appId = uni.getStorageSync("appId")
    let openId = store.getters.openId ? store.getters.openId : 'unknown'
    let deptId = getQueryString("deptId") == null ? "0" : getQueryString("deptId")
    reportApi.errorReport({ error: text, appId: appId, openId: openId, deptId });
};

//临时测试内容 可删除 开始
import Json from './Json' //测试用数据
const msg = (title, duration=1500, mask=false, icon='none')=>{
  //统一提示方便全局修改
  if(Boolean(title) === false){
    return;
  }
  uni.showToast({
    title,
    duration,
    mask,
    icon
  });
}
const json = type=>{
  //模拟异步请求数据
  return new Promise(resolve=>{
    setTimeout(()=>{
      resolve(Json[type]);
    }, 500)
  })
}

const prePage = ()=>{
  let pages = getCurrentPages();
  let prePage = pages[pages.length - 2];
  // #ifdef H5
  return prePage;
  // #endif
  return prePage.$vm;
}
Vue.prototype.$API = {msg, json, prePage};
//临时测试内容 可删除 结束



const app = new Vue({
  ...App,
  store,
});
app.$mount();
